const Koa = require('koa')
const Router = require('koa-router')
const Boom = require('boom')
const bodyParser = require('koa-bodyparser')

const app = new Koa()
const router = new Router()

app.use(router.routes())
app.use(router.allowedMethods({
  throw: true,
  notImplemented: () => new Boom.notImplemented(),
  methodNotAllowed: () => new Boom.methodNotAllowed()
}))

app.use(bodyParser())

// 模拟数据返回

const helloData = require('./home/hello.js')
router.get('/api/home/hello', async (ctx, next) => {
  ctx.body = helloData
  await next()
})

app.on('error', (err, ctx) => {
  console.log('server error', err, ctx)
})

app.listen(9999)
